#include<bits/stdc++.h>
#define For(i, a, b) for(register int i = (a); i <= (b); ++i)
#define Rof(i, a, b) for(register int i = (a); i >= (b); ++i)
#define For_Edge(i, x) for(auto i : edge[x])
#define For_Mul(i, a, b) for(register int i = (a); i <= (b); i += (a))
#define pii pair <int, int>
#define x1 _x
#define y1 _y
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
#define Size(a) ((int)a.size())
#define All(a) a.begin(), a.end()
using namespace std;
inline int read() {
    int x = 0;
    char c = getchar();
    bool f = 0;
    while(!isdigit(c)) f |= (c == '-'), c = getchar();
    while(isdigit(c)) x = (x * 10) + (c ^ 48), c = getchar();
    return f ? -x : x;
}
const int maxn = 3 * 1e6 + 5;
int n;
char S[maxn];
namespace Sub1 {
    int Answer;
    inline void Work() {
        Answer = 1;
        For(i, 1, n) 
            if(S[i] == 'B' && S[i + 1] == 'A') Answer++;
        printf("%d\n", Answer);
    }
}
namespace Sub2 {
    map <string, bool> mapp;
    inline void Search(string C) {
        if(mapp.count(C)) return ;
        mapp[C] = 1;
        int flag = 0, len = C.size(); string Cnt = C;
        For(i, 0, len - 2) {
            if(C[i] == 'A' && C[i + 1] == 'A') {
                C.erase(i, 2);
                Search(C), C = Cnt, flag = 1;
            }
            if(C[i] == 'B') {
                C.erase(i, 2);
                Search(C), C = Cnt, flag = 1;
            }
        }
        if(!flag) return ;
    }
    inline void Work() {
        string C;
        For(i, 1, n) C += S[i];
        Search(C);
        printf("%d\n", Size(mapp));
        /*
        for(auto i : mapp) {
            int len = Size(i.fi);
            For(j, 0, len - 1) printf("%c", i.fi[j]);
            printf("\n");
        }*/
    }
}
int main() {
    freopen("song.in", "r", stdin);
    freopen("song.out", "w", stdout);
    scanf("%s", S + 1);
    n = strlen(S + 1);
    int flag = 0;
    For(i, 1, n - 1)
        if(S[i] == S[i + 1]) flag = 1;
    if(flag) Sub2::Work();
    else Sub1::Work();
    return 0;
}

